<?php
  define('ACC', true);
require('./include/init.php');
session_start(); 
//print_r($_SESSION);
$userid = $_SESSION['user_id'];
//$userid = 26;

$company = new companymodel();
$companyinfo = $company->getcompanyinfo($userid);
$companyid = $companyinfo['company_id']; 
$company_y = $companyinfo['company_y'];
$company_q = $companyinfo['company_q'];


//$loaninfo = $company->getallelements($companyid, 'loan');
//$loaninfo = $company->getloan($companyid);  
$loanlist = $company->getelementlist('loan');

echo ' <div id = "loanapplication"><h4 class="modal-title">申请贷款</h4><form action = "#"><table class="table table-bordered">
          <tr><td>贷款类别</td><td>利率</td><td>期限(季度)</td><td>申请贷款金额输入</td> </tr>';

foreach($loanlist  as $k=>$v){
    $loanname = $v['element_name'];
    $duration =  $v['duration'];
    $interestrate = $v['interest_rate'];
                                                                                                                                                                               
    echo'<tr><td>' . $loanname . '</td><td>' . $interestrate . '</td><td>' . $duration . '</td><td><input type="text" id="' . $v['element_id']. '" /></td></tr>' ;
}                                                                                                                                                                                     
      
echo '</table></form></div><button type="button" id="applyforloan" class="btn btn-primary">提交</button><br/>';


echo '          
<script>
$("#applyforloan").click(function(){
               $.post("applyforloan1.php", 
                       {';
foreach($loanlist as $k=>$v){
    echo $v['element_id'] . ':$("#' . $v['element_id']  . '").val(),';
}     
echo '                       
                       },                 
                       function (data, textStatus){
                            $.each(data,function(name,value){ 
                            var anchor = "#" + name;
                            $(anchor).html(value);
                            })
                       },
                       "json",
                       $("#loan-modal-body").load("getloanupdate.php")
               );
          });
</script>
';

?>
